<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html lang="zh-CN">
    <head>
    <meta charset="utf-8">
        <%@ include file="/WEB-INF/views/include/head.jsp"%> 
        <link rel="stylesheet" href="${ctxStatic}/css/DateTimePicker.css">
        <link rel="stylesheet" href="${ctxStatic}/css/layerSm.css">
        <script type="text/javascript">
        
            $(document).ready(function(){
                selectInit();
            });
            
            function selectInit(){
            
             $("#sex").select2();
                 $("#country").select2();
                 $("#city").select2();
                 $("#role").select2();
            }
            //保存
            
            var saveForm={
                s:null,
                t:null,
                save:function(s,t){
                	$(t).attr("disabled",true);
                    this.s=s;
                    this.t=t;
                    $("#inputForm").validate({
                        submitHandler: function() {
                           var params = $("#inputForm").serialize();
                               $.post("${ctx}/sys/user/save",params,function(result){
                                    tipParent(result.message);
                                    if(result.statusCode==STATUSCODEOK){
                                        if(saveForm.s==1){
                                            $("#inputForm")[0].reset();  
                                            selectInit();
                                            $(saveForm.t).attr("disabled",false);
                                            window.parent.frames[0].location.reload();
                                            
                                        }else{
                                            window.parent.frames[0].location.reload();
                                            closeWin(); 
                                        }
                                      }else{
                                    	  $(saveForm.t).attr("disabled",false);
                                      }
                                 },'json');
                            },
                        rules: {
                            loginName: {remote: "${ctx}/sys/user/checkLoginName?oldLoginName=" + encodeURIComponent("${user.loginName}")},
                        },
                        messages: {
                            loginName: {remote: '<spring:message code="user_loginName_exist"/>'},
                        },
                        fail: function(element,e) {  
                        	$(saveForm.t).attr("disabled",false);
                        }
                    });
                    $("#inputForm").submit(); 
                } 
            }
              
             //城市联动
             function cityFun(t,id){
                 var code=$(t).find("option:selected").attr("data-value");
                 var param={"code":code};
                 $.post("${ctx}/sys/user/city",param,function(result){
                     var html="<option value=''><spring:message code="user_saveCityS"/></option>";
                     $.each(result,function(i,e){
                         html+="<option value='"+e.itemCode+"-"+e.itemValue+"'>"+e.itemName+"</option>";
                     });
                     $("#"+id).html(html);
                     $("#city").select2();
                 },'json');
             }
        </script>
    </head>
    <body>
        <div class="myshop clearfix">
            <p class="myshoptop fl">
                <!-- 修改店铺人员  --  创建店铺人员-->
                <c:choose>
                    <c:when test="${not empty user.id}"><spring:message code="user_editShopUser"/></c:when>
                    <c:otherwise><spring:message code="user_creatShopUser"/></c:otherwise>
                </c:choose>
            </p>
            <div class="fr">
                <div class="topBtnClose" onclick="closeWin()">
                    <img src="${ctxStatic}/images/btn-close.png">
                </div>
            </div>
        </div>
        <c:set value="<%=ResourcesUtil.getConfig(\"user_country\")%>" var="userCountry" />
        <c:set value="<%=ResourcesUtil.getConfig(\"user_sex\")%>" var="userSex" />
        <form id="inputForm" method="post">
            <input type="hidden" id="id" name="id" value="${user.id}"/>
            <input type="hidden" id="version" name="version" value="${user.version}"/>
            <div class="middle myshop_middle">
                <div class="data clearfix">
                    <div class="ch fl">
                        <div class="ch_middle fl haveToBox">
                        <!-- 姓 -->
                            <p class="data_id"><spring:message code="user_firstName"/></p>
                            <input type="text" id="firstName" name="firstName" value="${user.firstName}" maxlength="20" data-rule-required="true"  data-msg-required="<spring:message code="user_saveFirstName"/>" class="form-control fam" > 
                            <p class="haveTo">*</p>
                        </div>
                        <div class="ch_middle fr haveToBox">
                        <!-- 名字 -->
                            <p class="data_id"><spring:message code="user_lastName"/></p>
                            <input type="text" id="lastName" name="lastName" value="${user.lastName}" maxlength="20"  data-rule-required="true" data-msg-required="<spring:message code="user_saveLastName"/>"  class="form-control fam" >
                            <p class="haveTo">*</p>
                        </div>
                    </div>
                    <div class="ch fr">
                    <!-- 联系电话 -->
                        <p class="data_id"><spring:message code="user_telNo"/></p>
                        <input type="tel" id="telNo" name="telNo" value="${user.telNo}" class="form-control" maxlength="20" data-rule-nonnegativeInteger="true"  data-msg-nonnegativeInteger="<spring:message code="user_savetelNo"/>">
                    </div>
                </div>
                <div class="data clearfix">
                    <div class="ch fl">
                        <div class="ch_middle fl haveToBox">
                        <!-- 登录名 -->
                            <p class="data_id"><spring:message code="user_loginName"/></p>
                            <input type="text" id="loginName" name="loginName" data-rule-required="true" data-msg-required="<spring:message code="user_saveLoginName"/>" value="${user.loginName}" maxlength="20"  class="form-control fam" >
                            <input type="hidden" id="oldLoginName" name="oldLoginName" value="${user.loginName}" maxlength="20"  class="form-control fam">  
                            <p class="haveTo">*</p>
                        </div>
                        <c:choose>
                            <c:when test="${not empty user.id}"></c:when>
                            <c:otherwise>
                                <div class="ch_middle fr haveToBox">
                                <!-- 登录密码 -->
                                    <p class="data_id"><spring:message code="user_password"/></p>
                                    <input type="text" id="newPassword" name="newPassword" 
                                    data-rule-required="true" data-msg-required="<spring:message code="user_savePassWord"/>" 
                                    data-rule-banjiao="true" data-msg-banjiao="<spring:message code="user_pleaseInput_banjiao"/>" value="" class="form-control fam" maxlength="20" >
                                    <input type="hidden" id="password" name="password" value="${user.password}" class="form-control fam" >
                                    <p class="haveTo">*</p>
                                </div>
                            </c:otherwise>
                        </c:choose>
                    </div>
                    <div class="ch fr">
                        <!-- 联系传真 -->
                        <p class="data_id"><spring:message code="user_faxNo"/></p>
                        <input type="text" id="faxNo" name="faxNo" value="${user.faxNo}" class="form-control" maxlength="20" data-rule-nonnegativeInteger="true"  data-msg-nonnegativeInteger="<spring:message code="user_savefaxNo"/>">
                    </div>
                </div>
                <div class="data clearfix">
                    <div class="ch fl haveToBox">
                    <!-- 性别 -->
                        <p class="data_id"><spring:message code="user_sex"/></p>
                        <select id="sex" class="sex" name="sex" data-rule-required="true" data-msg-required="<spring:message code="user_savesex"/>" >
                            <option value=""><spring:message code="user_savesex"/></option>
                                <c:forEach items="${fns:getDictList(userSex)}" var="sex">
                                    <option  <c:if test="${fn:split(user.sex,'-')[1] eq sex.itemValue}">selected="selected"</c:if> value="${sex.itemCode}-${sex.itemValue}">
                                        ${sex.itemName}
                                    </option>
                                </c:forEach>
                        </select> 
                        <p class="haveTo">*</p>
                    </div>
                    
                    <div class="ch fr haveToBox">
                    <!-- Email -->
                        <p class="data_id">Email</p>
                        <input type="text"  id="email" name="email" data-rule-required="true" data-rule-email="true" data-msg-required="<spring:message code="user_saveEmail"/>"  data-msg-email="<spring:message code="user_saveEmail"/>" value="${user.email}" class="form-control" maxlength="30">
                        <p class="haveTo">*</p>
                    </div>
                </div>      
                <div class="data clearfix">
                    <div class="ch fl clearfix">
                        <!-- 出生日期 -->
                        <p class="data_id"><spring:message code="user_birthDate"/></p>
                        <div class="timeBox">
                            <input type="text" data-field="date" name="birthDate" class="form-control time" readonly value="<fmt:formatDate value="${user.birthDate}" pattern="yyyy-MM-dd"/>">
                        </div>
                    </div>
<!--                     <div class="ch fr clearfix">  -->
<!--                         <div class="ch_middle fl haveToBox"> -->
<!--                         所在国家 -->
<%--                             <p class="data_id"><spring:message code="user_country"/></p> --%>
<%--                             <select class="sex" id="country" name="country" data-rule-required="true" data-msg-required="<spring:message code="user_saveCountryName"/>" onchange="cityFun(this,'city')" > --%>
<%--                                 <option value=""><spring:message code="user_savecountry"/></option> --%>
<%--                                 <c:forEach items="${fns:getDictList(userCountry)}" var="country"> --%>
<%--                                     <option  data-value="${country.itemValue}" <c:if test="${fn:split(user.country,'-')[1] eq country.itemValue}">selected="selected"</c:if> value="${country.itemCode}-${country.itemValue}"> --%>
<%--                                             ${country.itemName} --%>
<!--                                    </option> -->
<%--                                 </c:forEach> --%>
<!--                             </select> -->
<!--                             <p class="haveTo">*</p> -->
<!--                         </div> -->
<!--                         <div class="ch_middle fr haveToBox"> -->
<!--                         所在城市 -->
<%--                             <p class="data_id"><spring:message code="user_city"/></p> --%>
<%--                             <select class="sex" id="city" name="city" data-rule-required="true" data-msg-required="<spring:message code="user_saveCityName"/>" > --%>
<%--                                 <option value=""><spring:message code="user_saveCity"/></option> --%>
<%--                                 <c:forEach items="${fns:getDictList(fn:split(user.country,'-')[1])}" var="city"> --%>
<%--                                     <option <c:if test="${fn:split(user.city,'-')[1] eq city.itemValue}">selected="selected"</c:if>  value="${city.itemCode}-${city.itemValue}"> --%>
<%--                                              ${city.itemName} --%>
<!--                                     </option> -->
<%--                                 </c:forEach>   --%>
<!--                             </select> -->
<!--                             <p class="haveTo">*</p> -->
<!--                         </div> -->
<!--                     </div>  -->
                </div>
                <div class="data clearfix">
                    <div class="ch fl">
                    <!-- 手机号码 -->
                        <p class="data_id"><spring:message code="user_mobile"/></p>
                        <input type="text" id="mobile" name="mobile" value="${user.mobile}" class="form-control" maxlength="20" data-rule-nonnegativeInteger="true"  data-msg-nonnegativeInteger="<spring:message code="user_savemobile"/>">
                    </div>
                    <div class="ch fr haveToBox">
                    <!-- 人员角色 -->
                        <p class="data_id"><spring:message code="user_role"/></p>
                        <select  id="role" name="role.id" class="sex" data-rule-required="true" data-msg-required="<spring:message code="user_saverole"/>">
                            <option value=""><spring:message code="user_saverole"/></option>
                            <c:forEach items="${allRoles}" var="allRole">
                                <option <c:if test="${user.role.id eq allRole.id}">selected="selected" </c:if>  value="${allRole.id}">
                                ${allRole.roleName}
                                </option>
                            </c:forEach>
                        </select> 
                        <p class="haveTo">*</p>
                    </div>
                </div>
                <div class="data clearfix">
                    <div class="ch fl">
                    <!-- 详细地址 -->
                        <p class="data_id"><spring:message code="user_address"/></p>
                        <textarea class="shopint" name="address"  maxlength="100" >${user.address}</textarea>
                    </div>
                    <div class="ch fr">
                    <!-- 备注 -->
                        <p class="data_id"><spring:message code="user_remarks"/>
                        <span class="txtRg">(0/100)</span>
                        </p>
                        <textarea class="shopint" name="remarks" maxlength="100" >${user.remarks}</textarea>
                    </div>
                </div>
                <div class="twobtn" style="margin-top:100px;">
                    <div class="onebtn clearfix">
                        <shiro:hasPermission name="sys:user:edit">
                            <button class="btn save fl" type="button" onclick="saveForm.save(0,this)" ><spring:message code="common_save"/></button>
                           
                            <c:if test="${empty user.id}">
                                <button  type="button" class="btn gon fr" onclick="saveForm.save(1,this)" ><spring:message code="common_save_continue"/></button>
                            </c:if>
                        </shiro:hasPermission>
                    </div>
                </div>
            </div>
        </form>
        <div id="dtBox1"></div>
        <script src="${ctxStatic}/DateTimePicker/DateTimePicker.js"></script>
        <script>
            var windowH = window.innerHeight
                ||document.documentElement.clientHeight
                ||document.body.clientHeight
                $('.middle').css('height',windowH - 50);

            $(document).ready(function() {
                $("#dtBox1").DateTimePicker({
                    dateFormat: "yyyy-MM-dd",
                    parentElement: ".timeBox",
                });

            });
        </script>
    </body>
</html>